/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2021.
 * Description: header for self-defined tracepoint.
 * Author: nixiaoming
 * Create: 2018-3-4
 */

#ifndef _RTOS_TRACEPOINT_H
#define _RTOS_TRACEPOINT_H

#include <linux/tracepoint.h>
#include <linux/msa.h>

#ifdef CONFIG_RTOS
/* Define the tracepoint here, if the feature does not have its own c file */

#ifdef CONFIG_RTOS_HAL_ENABLE_UART_RX_SWITCH
#include <linux/serial_core.h>
#ifndef CONFIG_TRACEPOINTS
#include <linux/notifier.h>
#endif

struct uart_rx_args {
	struct uart_port *port;
	unsigned int status;
	unsigned int overrun;
	unsigned int ch;
	unsigned int flag;
};
#ifdef CONFIG_TRACEPOINTS
DECLARE_TRACE(uart_insert_char,
	TP_PROTO(struct uart_rx_args *args), TP_ARGS(args));
#else
int register_trace_uart_insert_char(struct notifier_block *nb);
int unregister_trace_uart_insert_char(struct notifier_block *nb);
int trace_uart_insert_char(struct uart_rx_args *args);
#endif
#endif

#ifdef CONFIG_RTOS_RSM_SIGBUS
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/fs.h>

DECLARE_TRACE(sigbus_debug,
	TP_PROTO(int ret,  void *fault, struct vm_area_struct *vma, struct vm_fault *vmf, void *reserve),
	TP_ARGS(ret, fault, vma, vmf, reserve));
#endif

#ifdef CONFIG_RTOS_SIGNAL_HANDLE_TRACE
enum SA_HANDLER_RESET_FLAG {
	SIGNAL_SETUP_DONE,
	FORCE_SIG_INFO,
	FORCE_SIGSEGV,
	FLUSH_SIGNAL_HANDLERS
};

DECLARE_TRACE(sa_handler_reset,
	TP_PROTO(int sig, struct task_struct *t, enum SA_HANDLER_RESET_FLAG mode),
	TP_ARGS(sig, t, mode));
DECLARE_TRACE(sys_sigreturn_print,
	TP_PROTO(struct task_struct *t),
	TP_ARGS(t));
#endif

#ifdef CONFIG_RTOS_MICROSTATE_ACCT

#ifdef CONFIG_RTOS_MICROSTATE_ACCT_ON_SYSTEM_CALL
DECLARE_TRACE(space_switch,
	TP_PROTO(enum msa_thread_state state),
	TP_ARGS(state));
#else
#define trace_space_switch(x) do { } while (0)
#endif /* CONFIG_RTOS_MICROSTATE_ACCT_ON_SYSTEM_CALL */


DECLARE_TRACE(msa_irq_start,
	TP_PROTO(unsigned int irq, struct pt_regs *regs, void *pfunc),
	TP_ARGS(irq, regs, pfunc));
#else
#define trace_space_switch(x) do { } while (0)
#define trace_msa_irq_start(irq, regs, pfunc) do { } while (0)
#endif /* CONFIG_RTOS_MICROSTATE_ACCT */

/* action can be NULL if not available. */
#ifdef CONFIG_RTOS_TTY_STATUS_TRACE
#include <linux/tty.h>
DECLARE_TRACE(tty_status,
	      TP_PROTO(struct tty_struct *tty,
		       unsigned long stopped,
		       void *func),
	      TP_ARGS(tty, stopped, func));
#else
#define trace_tty_status(tty, stopped, func) do { } while (0)
#endif

#ifdef CONFIG_RTOS_TRACE_SENDMSG
#include <linux/inet.h>
#include <linux/socket.h>
DECLARE_TRACE(sendmsg,
	TP_PROTO(struct socket *sock, struct msghdr *msg, size_t len),
	TP_ARGS(sock, msg, len));
#endif

#ifdef CONFIG_RTOS_SKB_MEMLEAK_DFX
DECLARE_TRACE(kmem_cache_free_bulk,
	TP_PROTO(unsigned long call_site, struct kmem_cache *s, void **ptr, size_t size),
	TP_ARGS(call_site, s, ptr, size));
#endif

#endif
#endif
